package com.efrei.schoolmanager.tests.model.hibernate;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.efrei.schoolmanager.model.hibernate.HibernateUtil;
import com.efrei.schoolmanager.model.hibernate.dao.EleveDAO;
import com.efrei.schoolmanager.model.obj.Eleve;

/**
 * test le dao eleve
 * @author pierrick
 */
public class TestEleveDAO {

	public static void main(String[] args) {
		Session session = null;
		Transaction tx = null;
		try {
			session = HibernateUtil.getSession();
			//et ouverture de la transaction
			tx = session.beginTransaction();
		} catch (Exception e) {
			//connexion à la base impossible ?
			e.printStackTrace();
			return;
		}
		
		try {
			//init du DAO
			EleveDAO eleveDao = new EleveDAO(session);
			//recuperation des classes
			List<Eleve> eleves = eleveDao.getEleves();
			//utilisation de la classe
			for (Eleve eleve : eleves) {
				System.out.println(eleve);
			}
			//commit la transaction
			tx.commit();
		} catch (Exception e) {
			//erreur quelque part
			e.printStackTrace();
			tx.rollback();
		}
		System.out.println("Fin du test :D");
	}
}
